<?php

function i_group_overview(){
	$group_data = c_get_group_data();
	$html = '';
	$html .= '<div class="wrapper">'.
				'<div class ="header"></div>'.
				'<div class="mainPage">'.
					'<h2 style="margin-left:350px;">Group Overview</h2>';
	# display error messages
	if(has_errors()){
		$html .= '<br/><br/>';
		$err = i_get_msg_err();
		$ci = count($err);
		for($i=0; $i<$ci; $i++){
			$html .= '<div align="center" id="error_msg">' . $err[$i] . '</div>';
		}
	}
	else{
		$html .=	'<p>&nbsp;</p>'.
					'<table border=" " style="margin-left:250px;">'.
						'<tr>'.
							'<td><div align="right"><b>Group Name:</b></div></td>'.
							'<td style="padding-left:10px;">'.$group_data['name'].'</td>'.
						'</tr>'.
						'<tr>'.
							'<td><div align="right"><b>Group Description:</b></div></td>'.
							'<td style="padding-left:10px;">'.$group_data['desc'].'</td>'.
						'</tr>'.
						'<tr>'.
							'<td class="overview_participants">'.
								'<table>'.
									'<tr>'.
										'<td><p align="center"><u>-Participants-</u></p></td>'.
										'<td></td>'.
										'<td></td>'.
									'</tr>'.
									'<tr>'.
										'<td><p align="center"><b>'.$group_data['master_name'].'</b></p></td>'.
										'<td></td>'.
										'<td></td>'.
									'</tr>';
							
		$ci = sizeof($group_data['participants']);
		for($i = 0; $i<$ci; $i++)
		{
			$html .=				'<tr>'.
										'<td><p align="center">'.$group_data['participants'][$i].'</p></td>'.
										'<td></td>'.
										'<td></td>'.
									'</tr>';
		}
		
		if($_SESSION['user_id'] == $group_data['master_id'] & !empty($group_data['proposals'])){ // if user is group master, he can see user proposals as well
			$html .=				'<tr>'.
										'<td><p align="center"><u>-Proposals-</u></p></td>'.
										'<td></td>'.
										'<td></td>'.
									'</tr>';
			$ci = sizeof($group_data['proposals']);
			for($i = 0; $i<$ci; $i++)
			{
				$link = '?id='.$group_data['proposals'][$i]['part_id'].'&group_id='.$_GET['grp'].'&action='; // action 0 - decline, 1 - accept;
				$html .=			'<tr>'.
										'<td><p align="center">'.$group_data['proposals'][$i]['part_name'].'</p></td>'.
										'<td><a href="php/core/Group_overview/p_accept_user.php'.$link.'1">Accept</a></td>'.
										'<td><a href="php/core/Group_overview/p_accept_user.php'.$link.'0">Decline</a></td>'.
									'</tr>';
			}
		}
		$html .=				'</table>'.
							'</td>'.
							'<td>'.
								'<table border=" ">'.
									'<tr>'.
										'<td><div align="center">'.
										'<p><u>Assigned Meetings</u></p>'.
										'<table>'.
											'<tr>'.
												'<td width="100">Date</td>'.
												'<td width="75">Time</td>'.
												'<td width="75">Duration</td>'.
												'<td width="150">Place</td>'.
											'</tr>';
		$ci = sizeof($group_data['def_meetings']);
		for($i = 0; $i<$ci; $i++){
			$html .=						'<tr>'.
												'<td>'.$group_data['def_meetings'][$i]['date'].'</td>'.
												'<td>'.$group_data['def_meetings'][$i]['time'].'</td>'.
												'<td>'.$group_data['def_meetings'][$i]['duration'].'h</td>'.
												'<td>'.$group_data['def_meetings'][$i]['place'].'</td>'.
											'</tr>';
		}
		$html .=						'</table>'.
										'</div></td>'.
									'</tr>'.
									'<tr>'.
										'<td>'.
											'<br/>'.
											'<p align="center"><u>Proposed Meetings</u></p>'.
											'<table width="495">'.
												'<tr>'.
													'<td width="100">Min. time</td>'.
													'<td width="100">Max. time</td>'.
													'<td width="75">Duration</td>'.
													'<td width="150">Place</td>'.
													'<td></td>'.
												'</tr>';
		$ci = sizeof($group_data['prop_meetings']);
		for($i = 0; $i<$ci; $i++){
			$meeting = $group_data['prop_meetings'][$i];
			$html .=							'<tr>'.
													'<td>'.$meeting['min_date'].'</td>'.
													'<td>'.$meeting['max_date'].'</td>'.
													'<td>'.$meeting['duration'].'h</td>'.
													'<td>'.$meeting['place'].'</td>';
				// suggest button
			if($_SESSION['user_id'] == $group_data['master_id']){
				$href = 'index.php?id='.I_SUGGEST_TIME_FOR_MEETING.'&meet_id='.$meeting['meet_id'];
				$html .= 							'<td><a href="'.$href.'">Suggest</a></td>'; // ?meet_id='.$meeting['meet_id'].' // TODO create suggest page
			}
				// ready button
			elseif($meeting['status'] == false){
				$href = 'php/core/Group_overview/p_set_ready.php?meet_id='.$meeting['meet_id'].'&grp_id='.$_GET['grp'];
				$html .= 							'<td><a href="'.$href.'">Ready</a></td>';
			}
			else{ // empty cell
				$html .=							'<td></td>';
			}
			$html .=							'</tr>';
		}
		$html .=							'</table>'.
											'<p>&nbsp;</p>'.
										'</td>'.
									'</tr>'.
								'</table>'.
							'</td>'.
						'</tr>'.
						'<tr>';
		if($_SESSION['user_id'] == $group_data['master_id']){
			$href_manage = 'index.php?id=' . I_EDIT_GROUP . '&grp='.$_GET['grp'];
			$href_new = 'index.php?id=' . I_CREATE_MEETING . '&grp='.$_GET['grp'];
			
			$html .= 		'<td></td>'; // <a href="'.$href_manage.'">Group management</a>
			$html .=		'<td><a href="'.$href_new.'">New meeting</a></td>';
		}
		else{
			$html .=		'<td><a href="php/core/Group_overview/p_leave_group.php?grp='.$_GET['grp'].'">Leave group</a></td>'; // TODO create link
		}
		$html .=		'</tr>'.
					'</table>';
	}
	$html .=	' </div>'.
				'<div class="clear">&nbsp;</div>'.
			'</div>';
	return $html;
} 
?>






	 